package net.steam.easyjoboa.biz.impl;

import java.util.List;

import net.steam.easyjoboa.biz.AddressBookGroupBiz;
import net.steam.easyjoboa.dao.AddressBookGroupDao;
import net.steam.easyjoboa.entity.AddressGroup;
import net.steam.easyjoboa.entity.PageBeans;

public class AddressBookGroupBizImpl implements AddressBookGroupBiz {

	private AddressBookGroupDao addressBookGroupDao;
	
	public List<AddressGroup> getGroups(int loginId, PageBeans pageBeans,String addName) {
		
		String hql="from AddressGroup where 1=1";
		List<AddressGroup> list=null;
		if(loginId!=0){
			hql+=" and employee.userId="+loginId;
		}
		if(addName!=null&&!addName.equals("")){
			hql+=" and addressGroupName='"+addName+"'";
		}
		list = addressBookGroupDao.findByPage(pageBeans,hql);	
		
		return list;
	}
	
	public void addGroup(AddressGroup addressGroup) {
		try {
			addressBookGroupDao.addEntity(addressGroup);
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}

	public AddressGroup getGroupById(int id) {
		return addressBookGroupDao.findById(id);
	}

	public void update(AddressGroup addressGroup) {
		addressBookGroupDao.updateEntity(addressGroup);
		
	}	

	public List<AddressGroup> getAddressGroupByUserId(int id) {
		String hql="from AddressGroup where employee.userId="+id;
		return addressBookGroupDao.find(hql);
	}

	public void delete(AddressGroup addressGroup) {
		try {
			addressBookGroupDao.deleteEntity(addressGroup.getAddressGroupId());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public List<AddressGroup> getList(int loginId,int id) {
		String hql = "from AddressGroup where employee.userId="+loginId+"and addressGroupId !="+id;
		return addressBookGroupDao.find(hql);
	}

	public List<AddressGroup> getListByName(String name) {
		String hql ="from AddressGroup where addressGroupName='"+name+"'";
		return addressBookGroupDao.find(hql);
		
	}	
	
	public void setaddressBookGroupDao(AddressBookGroupDao addressBookGroupDao) {
		this.addressBookGroupDao = addressBookGroupDao;
	}


	
}
